<?php
class MozgSource
{
	private static $_sources = array();
	
	private function __construct(){}
	
	public static function get($sourceName)
	{
		if (!self::$_sources[$sourceName])
		{
			self::$_sources[$sourceName] = self::load($sourceName);
		}
			
		return self::$_sources[$sourceName];
	}
	
	private static function load($sourceName)
	{
		$sourceClassName = 'MozgSource_' .$sourceName;
		if (!class_exists($sourceClassName))
		{
			$classFileName = _APP_PATH. 'sources/source_' .strtolower($sourceName). '.php';
			if (!is_file($classFileName)) throw new Exception('Не найден source файл ' .$sourceName);
			include_once($classFileName);
		}
		
		if (!class_exists($sourceClassName)) throw new Exception('Не найден source класс ' .$sourceName);
		
		return new $sourceClassName();		
	}
}